package com.itheima.service.imp;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import com.itheima.mapper.EntifyMapper;

import com.itheima.pojo.EntifyQueryParam;
import com.itheima.pojo.Entity;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.PageResultwo;

import com.itheima.service.EntifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

@Service
public class EntifyServiceImpl implements EntifyService {

    @Autowired
    private EntifyMapper entifyMapper;


    @Override
    public PageResultwo listwo(EntifyQueryParam entifyQueryParam) {
        //1、分页设置
        PageHelper.startPage(entifyQueryParam.getPage(),entifyQueryParam.getPageSize());

        //3、执行查询
        List<Entity> listwo = entifyMapper.listwo(entifyQueryParam);
        Page<Entity> pageList = (Page<Entity>) listwo;

        //4、封装PageResult对象
        return new PageResultwo(pageList.getTotal(),pageList.getResult());
    }

    @Override
    public Integer add(Entity entity) {
        return entifyMapper.add(entity);
    }

    @Override
    public Integer delete(Integer id) {
        return entifyMapper.delete(id);
    }

    @Override
    public List<Entity> fandAll() {
        return entifyMapper.findAll();
    }

    @Override
    public Entity select(Integer id) {
        return entifyMapper.selectById(id);
    }

    @Override
    public Integer update(Entity entity) {
        return entifyMapper.update(entity);
    }
}
